package ldh.text.pane;

import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import ldh.text.controller.SmallDataTextAreaController;
import ldh.text.service.FileDataService;
import ldh.text.util.FxmlNodeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class SmallDataTextAreaPane extends StackPane {

    private static final Logger LOGGER = LoggerFactory.getLogger(SmallDataTextAreaPane.class);

    private File file;
    private FileDataService dataService;

    private SmallDataTextAreaController smallDataTextAreaController;

    public SmallDataTextAreaPane() {
        try {
            FxmlNodeUtil.FxmlNode<VBox, SmallDataTextAreaController> fxmlNode = FxmlNodeUtil.load(this.getClass().getResource("/fxml/SmallDataTextArea.fxml"));
            this.smallDataTextAreaController = fxmlNode.getController();
            this.getChildren().add(fxmlNode.getNode());
            dataService = new FileDataService();

            this.smallDataTextAreaController.setDataService(dataService);
        } catch (Exception e) {
            LOGGER.error("get file size error!", e);
        }
    }

    public SmallDataTextAreaPane(File file) {
        try {
            FxmlNodeUtil.FxmlNode<VBox, SmallDataTextAreaController> fxmlNode = FxmlNodeUtil.load(this.getClass().getResource("/fxml/SmallDataTextArea.fxml"));
            this.smallDataTextAreaController = fxmlNode.getController();
            this.getChildren().add(fxmlNode.getNode());
            dataService = new FileDataService(file);

            this.smallDataTextAreaController.setDataService(dataService);
        } catch (Exception e) {
            LOGGER.error("get file size error!", e);
        }
    }

    public void close() {

    }

    public File saveData() {
        return smallDataTextAreaController.saveData();
    }

    public void loadData(boolean isWrapText) {
        this.smallDataTextAreaController.loadData(isWrapText);
    }

    public void setWrapText(boolean selected) {
        this.smallDataTextAreaController.setWrapText(selected);
    }

    public void focus(){
        smallDataTextAreaController.focus();
    }
}
